package api

import (
	"client/global"
	"github.com/gin-gonic/gin"
	"server/proto"
	"strconv"
)

func EsAdd(c *gin.Context) {
	index := c.PostForm("index")
	name := c.PostForm("name")
	price := c.PostForm("price")
	inquire := c.PostForm("inquire")
	address := c.PostForm("address")
	img := c.PostForm("img")
	status := c.PostForm("status")
	i, _ := strconv.Atoi(inquire)
	_, err := global.RpcClient.EsAdd(c, &proto.EsAddReq{
		Index:        index,
		GoodsName:    name,
		GoodsPrice:   price,
		GoodsInquire: int64(i),
		GoodsAddress: address,
		GoodsStatus:  status,
		GoodsImg:     img,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": -1,
			"msg":  err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "success",
	})
	return
}
